package piccolo;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import edu.umd.cs.piccolo.nodes.PPath;

public class P2DWindow extends JFrame implements MouseListener{
	private static final long serialVersionUID = 3332344727452897393L;
	private P2DCanvas canvas = P2DCanvas.getInstance();
	private ZoomSlider zoom = ZoomSlider.getInstance();
	
	private static P2DWindow instance;
	private JScrollPane scroll;
	
	public final static int CANVAS_WIDTH = 2048;
	public final static int CANVAS_HEIGHT = 2048;
	
	public static P2DWindow getInstance()
	{
		if(instance==null) instance = new P2DWindow();
		return instance;
	}
	
	public void closeWindow()
	{
		this.dispose();
	}
	
	public P2DWindow()
	{
		super();
		this.setLayout(new BorderLayout());
		Dimension d = new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT);
		canvas.setSize(d);
		canvas.setPreferredSize(d);
		
		String gifImage = "src/gif/32x32/database.gif";
		ImageIcon imgIcon = new ImageIcon(gifImage);
		
		this.setIconImage(imgIcon.getImage());
		this.setJMenuBar(new Menu());
		this.add(canvas,BorderLayout.CENTER);
		this.add(zoom,BorderLayout.SOUTH);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setExtendedState(MAXIMIZED_BOTH);
		this.setVisible(true);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.println("CLICK!");
		int x = e.getX();
		int y = e.getY();
		
		PPath box = PPath.createRectangle(x, y, 100, 100);
		this.canvas.getLayer().addChild(box);
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
